import java.io.*;
import java.util.HashMap;
import java.util.Map;
import java.util.StringTokenizer;

public class 返回无序数组中正数和负数个数相等的最长子数组长度 {
    public static PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    public static Read in = new Read();
    public static int MAXN = 100001;
    public static int n,ans;
    public static int[] arr = new int[MAXN];
    public static Map<Integer,Integer> map = new HashMap<>(); // key 为前缀和大小, value 为最小下标
    public static void main(String[] args) throws IOException{
        n = in.nextInt(); // 读取数组长度
        map.put(0,-1); // 哈希表的初始化, 前缀和为 0 的时候, 下标为 -1
        ans = 0; // 最长长度
        for (int i = 0; i < n; i++) {
            arr[i] = in.nextInt(); // 读取数组
        }
        for (int i = 0,sum = 0; i < n; i++) {
            // 为 0 无需修改
            if (arr[i] < 0) {
                sum += -1; // 如果小于 0 , 代表为 -1
            } else if (arr[i] > 0) {
                sum += 1; // 大于 0 , 代表为 1
            }
            // 哈希表中存在前缀和为 sum , 就进行更新操作
            if (map.containsKey(sum)) {
                ans = Math.max(ans,i - map.get(sum));
            } else {
                // 不存在前缀和 sum , 更新一下存储最早出现 sum 的下标
                map.put(sum,i);
            }
        }
        out.println(ans);
        out.close();
    }



    public static class Read {
        StringTokenizer st = new StringTokenizer("");
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String next() throws IOException {
            while (!st.hasMoreTokens()) {
                st = new StringTokenizer(bf.readLine());
            }
            return st.nextToken();
        }

        int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        long nextLong() throws IOException {
            return Long.parseLong(next());
        }
    }
}
